package com.superatom.springboot.event;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;

/**
 * 创建一个启动Spring boot的监听器
 */
public class MyApplicationStartedEventListener implements ApplicationListener<ApplicationStartedEvent> {

    private static final Logger log = LoggerFactory.getLogger(MyApplicationStartedEventListener.class);

    @Override
    public void onApplicationEvent(ApplicationStartedEvent applicationStartedEvent) {
        // 在该事件中可以获取到SpringApplication对象，可做一些执行前的设置
        SpringApplication springApplication = applicationStartedEvent.getSpringApplication();
        log.info("-----调用ApplicationStartedEvent监听者-----");
    }
}
